package com.atguigu.springcloud.alibaba.controller;


import com.atguigu.springcloud.alibaba.service.StorageService;
import com.atguigu.springcloud.entities.CommonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@Slf4j
public class StorageController {

    @Value("${server.port}")
    private String port;

    @Resource
    private StorageService storageService;

    /**
     * 扣减库存
     */
    @GetMapping("/storage/decrease")
    public CommonResult decrease(@RequestParam("productId") Long productId, @RequestParam("count") Integer count) {
        storageService.decrease(productId, count);
        log.info("IP:" + port + ",扣减库存成功！");
        return new CommonResult(200, "IP:" + port + ",扣减库存成功！");
    }
}
